<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入评论内容。最多120字" maxlength="120" v-model="msg"></textarea>
        <mt-button type="primary" size="large" @click="postComment">发表评论</mt-button>
        <div class="cmt-list" v-for="(item,i) in comments" :key="item.db">
            <div class="cmt-item">
                <div class="cmt-title">
                    第{{i+1}}楼&nbsp;&nbsp;用户：{{item.dname}}&nbsp;&nbsp;发表时间：{{item.dataTime}}
                </div>
                <div class="cmt-body">
                    {{item.db}}
                </div>
            </div>
        </div>

        <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>
    </div>
</template>
<script>
import {Toast} from "mint-ui" 
export default {
    data(){
        return{
            app_key:'9701679D4CFB823670BA30DBEA0AE855',
            comments:[],
            page:1,
            msg:''
            }
    },
    created(){
        this.getCommentList()
    },
    methods:{
        getCommentList(){
            this.$jsonp('http://hd215.api.yesapi.cn/?&service=App.Table.FreeQuery&model_name=comment&logic=and&where=[["big", "=", "0"]]&order=1&page='+this.page+'&perpage=2&app_key='+this.app_key,{}
            ).then(res=>{
                this.comments=this.comments.concat(res.data.list)
                 
            })
            // $.ajax({
            //     url:"http://hd215.api.yesapi.cn/?service=App.Main_Set.GetList&key=%E8%AF%84%E8%AE%BA&page=1&perpage=10&sort=1&app_key=9701679D4CFB823670BA30DBEA0AE855&sign=ED2329056910F2C4CDDCA5363AD525F8",
            //     type:"GET",
            //     dataType:"jsonp",
            //     success:function(res){
            //         console.log(res.data.items[0].data)
            //         self.comments=res.data.items[0].data
            //     }
            // })
        },
        getMore(){
            this.page++;
            this.getCommentList();
        },
        postComment(){
            if(this.msg.trim().length===0){
                return Toast("评论不能为空!");
            }
             
        }
    }
}       
</script>
<style lang="scss" scoped>
.cmt-container{
    h3{
        font-size:18px;
    }
    textarea{
        font-size:14px;
        height:85px;
        margin: 0;
    }
    .cmt-list{
        margin: 5px 0; 
        .cmt-item{
            font-size: 13px;
            .cmt-title{
                background: #ccc;
            }
            .cmt-body{
                line-height: 30px;
                text-indent: 2em;
            }
        }
    }
}

</style>
